const path = require('path')

const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    mode: 'development',
    entry: {
        books: './src/pages/books/index.js',
        add: './src/pages/add/index.js',
        update: './src/pages/update/index.js'
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'js/[name]_[contenthash:8].js',
        clean: true
    },
    module: {
        rules: [{
                test: /\.art$/,
                use: 'art-template-loader'
            },
            {
                test: /\.js$/,
                exclude: /node_modules/, // 不进行处理的文件夹
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: [
                            [
                                '@babel/preset-env',
                                {
                                    useBuiltIns: 'usage', // 只打包使用的ES6新API的实现代码
                                    corejs: {
                                        version: 2
                                    } // 指定core-js的版本号为2
                                }
                            ]
                        ], // 指定bebel预设包
                        plugins: [], // 指定babel插件包
                    }
                }
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/pages/index.html',
            inject: 'body'
        }),
        new HtmlWebpackPlugin({
            template: './src/pages/books/index.html',
            filename: 'books.html',
            inject: 'body',
            chunks: ['books']
        }),
        new HtmlWebpackPlugin({
            template: './src/pages/add/index.html',
            filename: 'add.html',
            inject: 'body',
            chunks: ['add']
        }),
        new HtmlWebpackPlugin({
            template: './src/pages/update/index.html',
            filename: 'update.html',
            inject: 'body',
            chunks: ['update']
        })
    ],
    devServer: {
        port: 5000,
        open: true
    },
    devtool: 'source-map'

}